<template>
  <section class="login">
    <!-- 登录导航栏 -->
    <router-link to="/">
      <van-nav-bar title="登录" left-arrow @click-left="onClickLeft" />
    </router-link>
    <van-cell-group class="login-form">
      <van-field
        v-model="username"
        left-icon="user-o"
        placeholder="请输入账号"
        class="login-field"
      />
      <van-field
        v-model="password"
        clearable
        type="password"
        left-icon="lock"
        placeholder="请输入密码"
        class="login-field"
      />
    </van-cell-group>
    <!-- 登录按钮 -->
    <van-button type="primary" @click="login" block class="login-button">
      登录
    </van-button>
    <!-- 跳转到注册页 -->
    <div class="login-options">
      <router-link to="/register" class="login-link">
        <span class="register">点击注册</span>
      </router-link>
      <span class="forgetPassword">忘记密码</span>
    </div>
  </section>
</template>

<script>
import { ILogin } from "../api/request.js";
export default {
  name: "Login",
  props: {
    onClickLeft: {
      type: Function,
      default: () => {},
    },
  },
  data() {
    return {
      username: null,
      password: null,
    };
  },
  beforeMount() {
    localStorage.removeItem("token");
    this.username = this.$store.state.username;
  },
  methods: {
    login() {
      ILogin("/wx/auth/login", {
        username: this.username,
        password: this.password,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  .login-form {
    width: 300px;
    margin: 30px auto;
    margin-top: 30px;
  }

  .login-field {
    margin-bottom: 10px;
  }

  .login-form .login-field {
    background-color: rgba(212, 209, 209, 0.397);
    border-radius: 20px;
  }

  .login-button {
    background-color: #fac27b;
    width: 300px;
    margin: 30px auto;
    border-radius: 20px;
    border: #fac27b;
  }

  .login-options {
    font-size: 10px;

    .login-link {
      color: #1f76d2;
      text-decoration: none;
    }
  }

  .register {
    margin-left: 55px;
  }

  .forgetPassword {
    margin-left: 200px;
  }
}
</style>
